package logic

import (
	"context"
	"fmt"
	"good_srv/good"
	"good_srv/internal/svc"
	"good_srv/models"

	"github.com/zeromicro/go-zero/core/logx"
)

type ActiveAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewActiveAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ActiveAddLogic {
	return &ActiveAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ActiveAddLogic) ActiveAdd(in *good.ActiveAddRequest) (*good.ActiveAddResponse, error) {
	// todo: add your logic here and delete this line
	var err error
	a := models.Active{
		Title:     in.Title,
		Price:     float64(in.Price),
		Num:       int(in.Num),
		Address:   in.Address,
		Tel:       in.Tel,
		Progress:  int(in.Progress),
		Countdown: in.Countdown,
		Image:     in.Image,
	}
	if err = a.ActiveAdd(); err != nil {
		logx.Error("活动添加失败")
		return nil, fmt.Errorf("活动添加失败")
	}
	return &good.ActiveAddResponse{
		Id: int64(a.ID),
	}, nil
}
